var url, type, delta, _page_urls = require("page_urls"), _page_urls2 = _interopRequireDefault(_page_urls), _tools = require("tools");

function _interopRequireDefault(e) {
    return e && e.__esModule ? e : {
        default: e
    };
}

function toPage() {
    if (-1 != (url = setUrl())) switch (type) {
      case "navigate":
        wx.navigateTo({
            url: url,
            fail: function(e) {
                console.log(e);
            }
        });
        break;

      case "reLaunch":
        wx.reLaunch({
            url: url,
            fail: function(e) {
                console.log(e);
            }
        });
        break;

      case "redirect":
        wx.redirectTo({
            url: url,
            fail: function(e) {
                console.log(e);
            }
        });
        break;

      case "switchTab":
        wx.switchTab({
            url: url,
            fail: function(e) {
                console.log(e);
            }
        });
        break;

      case "navigateBack":
        wx.navigateBack({
            delta: delta,
            fail: function(e) {
                console.log(e);
            }
        });
    }
}

function setUrl() {
    var e = getApp();
    console.log(_page_urls2)
    switch (url) {
      case "/law_settling_in":
        var t = e.userInfo;
        if (3 == t.is_law && 0 == t.sh_state) return e.toast("审核中,请耐心等待"), -1;
        if (3 == t.is_law && 1 == t.sh_state) return e.item = {
            title: "申请驳回",
            content: t.jujue_content,
            img: "pay_no",
            button: [ {
                title: "返回首页",
                url: "loading",
                type: "reLaunch"
            }, {
                title: "重新申请",
                url: "enter",
                type: "redirect"
            } ]
        }, "/" + _page_urls2.default.result;
        if (3 != t.is_law) return "/" + (2 == t.is_law && 2 == t.sh_state ? _page_urls2.default.l_index : _page_urls2.default.enter);
        break;

      case "/fenxiao_settling_in":
        for (var r = e.dataNav.tabbar, a = 0; a < r.length; a++) if ("fenxiao_settling_in" == r[a].url) {
            type = "redirect";
            break;
        }
        if (!e.system.fx_state) return e.toast("未开启该功能"), -1;
        switch (parseInt(e.userInfo.is_distributor)) {
          case 1:
            return "/" + _page_urls2.default.f_index;

          case 2:
            return e.toast("审核中,请耐心等待"), -1;

          case 3:
            return "/" + _page_urls2.default.f_index;

          case 4:
            return e.item = {
                title: "申请驳回",
                content: e.userInfo.fx_jujue_content,
                img: "pay_no",
                button: [ {
                    title: "返回首页",
                    url: "loading",
                    type: "reLaunch"
                }, {
                    title: "重新申请",
                    url: "f_enter",
                    type: "redirect"
                } ]
            }, "/" + _page_urls2.default.result;
        }
        break;

      case "/contact":
        return -1;
    }
    if (url && -1 != url.indexOf("minapp:appid=")) {
        var l = (l = url.split(":")[1]).split("&");
        return wx.navigateToMiniProgram({
            appId: l[0] ? l[0].split("=")[1] : "",
            path: l[1] ? l[1].split("=")[1] : "",
            fail: function(e) {
                wx.showToast({
                    title: e,
                    icon: "none"
                });
            }
        }), -1;
    }
    if (url && -1 != url.indexOf("web:http")) {
        type = "navigate";
        l = encodeURIComponent(url.substr(5));
        return "/" + _page_urls2.default.web + "?url=" + l;
    }
    return url;
}

module.exports = function(e) {
    var t = e.a || e.params || "";
    if (url = _page_urls2.default[e.url] ? "/" + _page_urls2.default[e.url] : e.url, 
    type = e.type || "navigate", delta = e.delta || 1, t) for (var r in t) url += (-1 == url.indexOf("=") ? "?" : "&") + r + "=" + t[r];
    if (!(url = url && (0 != url.indexOf("/") ? "/" + url : url)) || -1 == url.indexOf("tel:")) return e.term || url == "/" + _page_urls2.default.lawyer_orders || url == "/" + _page_urls2.default.orders ? (0, 
    _tools.verifyLogin)({
        success: function() {
            return toPage();
        }
    }) : void toPage();
    wx.makePhoneCall({
        phoneNumber: url.split(":")[1],
        fail: function() {}
    });
};